package com.zhaodao.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.WebApplicationContext;

import java.util.HashMap;

/**
 * 描述:
 * 查看容器对象
 *
 * @author brozer
 * @create 2019-12-24 9:18
 */
@Controller
public class HelpController {

	//在子容器中 注入一个 WebApplicationContext 的实例
	@Autowired
	private WebApplicationContext webApplicationContext;

	@RequestMapping(path = "/Ioc",method = RequestMethod.GET)
	@ResponseBody
	public HashMap<String,String[]> allInIoc(){
		return new HashMap<String, String[]>(){{
			put("子容器",webApplicationContext.getBeanDefinitionNames());
			RedisMessageListenerContainer bean = webApplicationContext.getBean(RedisMessageListenerContainer.class);
			System.out.println(bean);
			//put("父容器", Objects.requireNonNull(webApplicationContext.getParent()).getBeanDefinitionNames());
		}};
	}
}
